# -*- coding: utf-8 -*-


# 提取武汉市植被类型栅格数据


import arcpy
import os
from arcpy.sa import *

inRaster = u"E:\\毕设数据\\wuhan_shp\\武汉市植被类型分布\\vegetation_type.tif"
out_root = u"E:\\毕设数据\\wuhan_shp\\武汉市植被类型分布\\vegetation_type"

values = [u'灌丛', u'阔叶', u'其他', u'栽培', u'针叶']


def extract(value):
    arcpy.CheckOutExtension("Spatial")
    inSQLClause = """"ZBDL"='%s'""" %value
    filename = value + ".tif"
    save_name = os.path.join(out_root, filename)
    if not os.path.exists(out_root):
        os.makedirs(out_root)
    print save_name
    print inSQLClause
    attExtract = ExtractByAttributes(inRaster, inSQLClause)
    attExtract.save(save_name)

# "ZBDL" = '灌丛' '阔叶' '其他' '栽培' '针叶'
if __name__ == '__main__':
    for i in values:
        extract(i)
